<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.name" placeholder="姓名"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getUsers">查询</el-button>
				</el-form-item>		
			</el-form>
		</el-col>
		<!--列表-->
		<el-table :data="users" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column type="index" width="60" >
			</el-table-column>
			<el-table-column prop="realname" label="姓名" width="120" >
			</el-table-column>
			<el-table-column prop="sex" label="性别" width="100" :formatter="formatSex" >
			</el-table-column>
			<el-table-column prop="age" label="年龄" width="100" >
			</el-table-column>
			<el-table-column prop="tel" label="联系方式" width="150" >
			</el-table-column>
            <el-table-column prop="n_time" label="预约时间" width="150" sortable>
			</el-table-column>
            <el-table-column prop="morbidity" label="病情简介" min-width="200" >
			</el-table-column>
			<el-table-column label="操作" width="200">
				<template scope="scope">
					<el-button type="primary" size="small" @click="receive(scope.$index, scope.row)">接收</el-button>
					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
			<el-pagination
			@size-change="handleSizeChange"
			@current-change="handleCurrentChange"
			:current-page="pageNum"
			:page-sizes="[3, 5, 10, 20]"
			:page-size="pageSize"
			layout="total, sizes, prev, pager, next, jumper"
			:total="total"
			style="float:right;">
			</el-pagination>
		</el-col>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	import { getPatient, removePatient, batchRemovePatient,changestatus} from '../../api/api';

	export default {
		data() {
			return {
				filters: {
					name: ''
				},
				users: [],
				total: 0,//列表总条数
				pageNum:1,//当前页码
				pageSize:3,
				listLoading: false,
				sels: [],//列表选中列
			}
		},
		methods: {
            //性别显示转换
			formatSex: function (row, column) {
				return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
			},
			handleSizeChange(val) {
				this.pageSize = val;
				this.getUsers();
			},
			handleCurrentChange(val) {
				this.pageNum = val;
				this.getUsers();
			},
			//获取病号列表
			getUsers() {
				var user = sessionStorage.getItem('user');
				user = JSON.parse(user);
				let para = {
					doctorid: user.did,
					status : 0,
					pageSize:this.pageSize,
					pageNum:this.pageNum,
					name:this.filters.name,

				};
				this.listLoading = true;
				getPatient(para).then((res) => {
					this.total = res.data.total
					this.users = res.data.list;
					this.listLoading = false;
				});
			},
		    //删除
			handleDel: function (index, row) {
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					let para = { n_id : row.n_id };
					removePatient(para).then((res) => {
						this.listLoading = false;
						 if (res.code !== 0) {
                                this.$message({
                                message : res.msg,
                                type : 'error'
                                });
                            } else {
                                this.$message({
                                    message : res.msg,
                                    type : 'success'
                            });
                        };
						this.getUsers();
					});
				}).catch(() => {

				});
			},
		    selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
				var n_id = this.sels.map(item => item.n_id).toString();
				this.$confirm('确认删除选中记录吗？', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					let para = { n_id: n_id };
					batchRemovePatient(para).then((res) => {
						this.listLoading = false;
						if (res.code !== 0) {
                            this.$message({
                            message : res.msg,
                            type : 'error'
                            });
                        } else {
                            this.$message({
                            message : res.msg,
                            type : 'success'
                        	});
                        };
						this.getUsers();
					});
				}).catch(() => {

				});
			},
			//接收病号
            receive:function(index, row){
				var user = sessionStorage.getItem('user');
				user = JSON.parse(user);
				let para = {
					doctorid: user.did,
					oid:row.oid,
					sts:1
				};
				this.listLoading = true;
				changestatus(para).then((res) => {
					this.listLoading = false;
                	let { code,msg  } = res;
						if (code !== 0) {
							this.$message({
							message: msg,
							type: 'error'
							});
						} else {
							this.$message({
								message: '接收成功',
								type: 'success'
							});
						}
					this.getUsers();
				});
            }
		},
		mounted() {
			this.getUsers();
		}
	}

</script>

<style scoped>

</style>